﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgileTimeTracker.Domain.Common;
using AgileTimeTracker.Domain.UserModule;

namespace AgileTimeTracker.Domain.TaskModule
{
    [Serializable]
    public class TfsTask : BaseEntity
    {
        public TfsTask()
        {
            this.WorkTimes = new List<TfsTaskWorkTime>();
        }

        public int? TfsWorkItemId { get; set; }

        public string Description { get; set; }

        public string Title { get; set; }

        public string IterationPath { get; set; }

        public string UserStory { get; set; }

        public bool WorkingTask { get; set; }

        public double CompletedWork { get; set; }

        public double RemainingWork { get; set; }

        public double EstimatedWork { get; set; }

        public List<TfsTaskWorkTime> WorkTimes { get; set; }

        public double TotalWorkTime
        {
            get
            {
                if (this.WorkTimes == null)
                {
                    return 0;
                }

                return this.WorkTimes.Where(t => t.EndDate.HasValue).Sum(t => (t.EndDate.Value - t.StartDate).TotalHours);
            }
        }

        public double TotalWorkTimeToday
        {
            get
            {
                if (this.WorkTimes == null)
                {
                    return 0;
                }

                var today = DateTime.Today;
                return this.WorkTimes.Where(t => t.EndDate.HasValue && t.StartDate.Date == today).Sum(t => (t.EndDate.Value - t.StartDate).TotalHours);
            }
        }
    }
}
